package com.example.demo.service;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class FileChannelIn {
    public static void main(String[] args) {
        try(FileInputStream in = new FileInputStream("E:\\temp\\hello.txt"); FileChannel channel = in.getChannel();) {
            ByteBuffer buffer = ByteBuffer.allocate(11);
            channel.read(buffer);
            buffer.flip();
            byte[] dist = new byte[11];
            buffer.get(dist);
            System.out.println(new String(dist));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
